package com.jiulong.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;

public class BaseController {
	private ControllerResponse cRes = new ControllerResponse();
	public void setStatus(int status) {
		cRes.setStatus(status);
	}

	public void setMessage(String message) {
		cRes.setMessage(message);
	}

	public void setStatus(int status, String message) {
		cRes.setStatus(status);
		cRes.setMessage(message);
	}

	public void setBody(Object body) {
		cRes.setBody(body);
	}

	public void addData(String key, Object value) {
		cRes.addData(key, value);
	}

	public void setTotal(int total) {
		cRes.setTotal(total);
	}

	
	
	public void setDataList(List<?> list) {
		cRes.setDataList(list);
	}

	protected void renderData(HttpServletResponse response) {
		PrintWriter printWriter = null;
		response.setCharacterEncoding("UTF-8"); 
		try {
			printWriter = response.getWriter();
			printWriter.print(JSON.toJSONString(cRes));
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			if (null != printWriter) {
				printWriter.flush();
				printWriter.close();
			}
		}
	}
}
